package com.aopcinemas.visitor.behaviour;

import jade.content.lang.Codec.CodecException;
import jade.content.onto.OntologyException;
import jade.content.onto.basic.Action;
import jade.core.Agent;
import jade.lang.acl.ACLMessage;
import jade.proto.AchieveREInitiator;

import com.aopcinemas.cinema.ontology.OrderRequest;
import com.aopcinemas.visitor.VisitorAgent;

public class OrderRequestInitiator extends AchieveREInitiator {

    private static final long serialVersionUID = 1L;

    public OrderRequestInitiator(Agent a, ACLMessage msg) {
        super(a, msg);
    }

    @Override
    protected void handleInform(ACLMessage inform) {
        try {
            VisitorAgent agent = (VisitorAgent) myAgent;
            Action action = (Action) agent.getContentManager().extractContent(inform);
            OrderRequest request = (OrderRequest) action.getAction();

            agent.notifyMessage("You have ordered for " + request.getInvoice().getPrice() + " EUR");

        } catch (CodecException e) {
            e.printStackTrace();
        } catch (OntologyException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void handleRefuse(ACLMessage refuse) {
        VisitorAgent agent = (VisitorAgent) myAgent;
        agent.notifyMessage(refuse.getContent());
    }

}
